home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / utility / ffe101.zip / GRAPH.SWG / 0025_DWG.pas < prev    next >
Pascal/Delphi Source File  |  1997-02-15  |  11KB  |  347 lines

  1. DWG file format
  2.  
  3. An attempt to specify the DWG (R12) file format using the BFF grammar for
  4. binary files.
  5.  
  6. Acknowledgements
  7.  
  8. I would like to thank Reini Urban <rurban@sbox.tu-graz.ac.at> for his
  9. contributions.
  10.  
  11. Definition of the elementary elements
  12.  
  13. typedef word word :=
  14.      byte : b1, byte : b2
  15.      return (word)f | ((word)s << 8).
  16. typedef longword longp :=
  17.      byte : b1, byte : b2, byte : b3, byte : b4
  18.      return (longword)b1 | ((longword)b2 << 8)
  19.           | ((longword)b3 << 16) | ((longword)b4 << 24).
  20. typedef longword longword :=
  21.      byte : b1, byte : b2, byte : b3, byte : b4
  22.      return (longword)b1 | ((longword)b2 << 8)
  23.           | ((longword)b3 << 16) | ((longword)b4 << 24).
  24.  
  25. Definition of the whole file
  26.  
  27. root dwg_file :=
  28.  [begin : end](
  29.   char[12] : version,
  30.   byte, word, word, word, byte,
  31.   longp : p_entities,  longp : p_entend,
  32.   longp : p_blocksec,  byte[4],  longp : p_bsend,  byte[4],
  33.   tablepos : block_table,
  34.   tablepos : layer_table,
  35.   tablepos : style_table,
  36.   tablepos : ltype_table,
  37.   tablepos : view_table,
  38.   header,  [cur : 0x3EF]byte*,
  39.   tablepos : ucs_table,  [cur : 0x500]byte*,
  40.   tablepos : vport_table,  byte[8],
  41.   tablepos : appid_table,  byte[6],
  42.   tablepos : dimstyle_table,  [cur : 0x69F]byte*,
  43.   tablepos : p13_table,  bytes[38],
  44.   [p_entities : p_entend]entities : ents,   byte[19],
  45.   [block_table.start : ]blocks : block_table,
  46.   [layer_table.start : ]layers : layer_table,
  47.   [style_table.start : ]styles : style_table,
  48.   [ltype_table.start : ]ltypes : ltype_table,
  49.   [view_table.start : ]table : view_table,
  50.   [ucs_table.start : ]table : ucs_table,
  51.   [vport_table.start : vport_table.end]table : vport_table,
  52.   [appid_table.start : ]appids : appid_table,
  53.   [dimstyle_table.start : ]table : dimstyle_table,
  54.   [p13_table.start : ]table : p13_table,
  55.   [p_blocksec : p_bsend]entities : blocks,  bytes[36],
  56.   longp = p_entities,  longp = p_entend,
  57.   longp = blocksec,  longp = bsend,
  58.   bytes[12],
  59.   bytes[6],
  60.   longp = block_table.start,   bytes[6],
  61.   longp = layer_table.start,   bytes[6],
  62.   longp = style_table.start,   bytes[6],
  63.   longp = ltype_table.start,   bytes[6]
  64.   longp = view_table.start,   bytes[6],
  65.   longp = ucs_table.start,   bytes[6],
  66.   longp = vport_table.start,   bytes[6],
  67.   longp = appid_table.start,   bytes[6],
  68.   longp = dimstyle_table.start,   bytes[6],
  69.   longp = p13_table.start,   bytes[6],
  70.   longp  bytes*,
  71.  ).
  72.  
  73. A table position
  74.  
  75. tablepos :=
  76.    word : size,
  77.    long : nr,
  78.    long : start,
  79.  
  80. The header
  81.  
  82. header :=
  83.    word,
  84.    point(TRUE) : inbase,
  85.    point(TRUE) : extmin,
  86.    point(TRUE) : extmax,
  87.    point(FALSE) : limmin,
  88.    point(FALSE) : limmax,
  89.    double[4],
  90.    byte[2],
  91.    double[2],
  92.    byte[56],
  93.    double[3],
  94.    byte[18],
  95.    double .
  96.  
  97. The block table
  98.  
  99. blocks :=
  100.   ( [size](
  101.       byte : flag,
  102.       char[32] : name,
  103.       word : used,
  104.       byte, word, byte, word,
  105.       check_2
  106.     )
  107.   )[nr] : blocks_info,
  108.   check_32.
  109.  
  110. check_2 := byte[2].
  111. check_32 := byte[32].
  112.  
  113. The layer table
  114.  
  115. layers :=
  116.   ( [size](
  117.       byte : flag,
  118.       char[32] : name,
  119.       word : used,
  120.       word : color,
  121.       word : style,
  122.       check_2
  123.     )
  124.   )[nr] : layer_info,
  125.   check_32.
  126.  
  127. The style table
  128.  
  129. styles :=
  130.   ( [size](
  131.       byte : flag,
  132.       char[32] : name,
  133.       word, double[3], byte, double, char[128],
  134.       check_2
  135.     )
  136.   )[nr] : style_info,
  137.   check_32.
  138.  
  139. The line-type table
  140.  
  141. ltypes :=
  142.   ( [size](
  143.       byte : flag,
  144.       char[32] : name,
  145.       word,  char[48],  byte,
  146.       byte,  double[13],
  147.       check_2
  148.     )
  149.   )[nr] : ltype_info,
  150.   check_32 .
  151.  
  152. The application identifier table
  153.  
  154. appids :=
  155.   ( [size](
  156.       byte : flag,
  157.       char[32] : name,
  158.       word,
  159.       check_2
  160.     )
  161.   )[nr] : appid_info,
  162.   check_32 .
  163.  
  164. The other tables
  165.  
  166. table :=
  167.   ( [size](
  168.       byte : flag,
  169.       [size - 3]byte*,
  170.       check_2
  171.     )
  172.   )[nr],
  173.   check_32 .
  174.  
  175. The entities
  176.  
  177. (Experimental)
  178.  
  179. entities :=
  180.   ( byte : kind,
  181.     byte : flag,
  182.     word : length,
  183.     [length - 4](
  184.       word : layer,
  185.       word : opts,
  186.       if (flag & 1) then byte : color else color = 0 fi,
  187.       if (flag & 0x40) then byte : extra else extra = 0 fi,
  188.       if (extra & 2) then xdata fi,
  189.       if (flag & 2) then word : type fi,
  190.       if (flag & 4 && kind > 2 && kind != 22) then double : z fi,
  191.       if (flag & 8) then double : th fi,
  192.       if (flag & 0x20) then handle fi,
  193.       if (extra & 4) then word : paper fi,
  194.       switch (kind)
  195.       case 1:  /* LINE */
  196.         point(!(flag & 4)) : l10,
  197.         point(!(flag & 4)) : l11,
  198.         if (opts & 1) then point(TRUE) : l210 fi,
  199.         if (opts & 2) then double : l38 fi,
  200.       case 2:  /* POINT */
  201.         point(!(flag & 4)) : l10,
  202.         if (opts & 1) then point(TRUE) : l210 fi,
  203.         if (opts & 2) then double : l38 fi,
  204.       case 3:  /* CIRCLE */
  205.         point(FALSE) : l10,
  206.         double : l40,
  207.         if (opts & 1) then point(TRUE) : l210 fi,
  208.         if (opts & 2) then double : l38 fi,
  209.       case 4:  /* SHAPE */
  210.         point(FALSE) : l10,
  211.         word : l2,
  212.         if (opts & 1) then point(TRUE) : l210 fi,
  213.         if (opts & 2) then double : l38 fi,
  214.       case 7: /* TEXT */
  215.         point(FALSE) : l10,
  216.         double : l40,
  217.         string : l1,
  218.         if (opts & 1) then double : l50 fi,
  219.         if (opts & 2) then double : l41 fi,
  220.         if (opts & 4) then double : l51 fi,             /*?*/
  221.         if (opts & 8) then byte : l7 fi,
  222.         if (opts & 0x10) then byte : l71 fi,
  223.         if (opts & 0x20) then byte : l72 fi,
  224.         if (opts & 0x40) then point(FALSE) : l11 fi,
  225.         if (opts & 0x100) then byte : l73 fi,
  226.       case 8:  /* ARC */
  227.         point(FALSE) : l10,
  228.         double : l40,
  229.         double : l50,
  230.         double : l51,
  231.         if (opts & 1) then point(TRUE) : l210 fi,
  232.         if (opts & 2) then double : l38 fi,
  233.       case 9:   /* TRACE */
  234.         point(FALSE) : l10,
  235.         point(FALSE) : l11,
  236.         point(FALSE) : l12,
  237.         point(FALSE) : l13,
  238.         if (opts & 1) then point(TRUE) : l210 fi,
  239.         if (opts & 2) then double : l38 fi,
  240.       case 11:   /* SOLID */
  241.         point(FALSE) : l11,
  242.         point(FALSE) : l12,
  243.         point(FALSE) : l13,
  244.         point(FALSE) : l14,
  245.         if (opts & 1) then point(TRUE) : l210 fi,
  246.         if (opts & 2) then double : l38 fi
  247.       case 12:   /* BLOCK */
  248.         point(FALSE) : l10,                /*?*/
  249.         string : l1,                       /* if (opts & 1) then ? */
  250.         if (opts & 2) then string : l3 fi
  251.       case 13:  /* ENDBLK */
  252.       case 14:   /* INSERT */
  253.         word : l1,
  254.         point(FALSE) : l10,
  255.         if (opts & 1) then double : l41 fi,
  256.         if (opts & 2) then double : l42 fi,
  257.         if (opts & 4) then double : l43 fi,
  258.         if (opts & 8) then double : l50 fi,
  259.         if (opts & 0x10) then byte : l70 fi,                /*?*/
  260.         if (opts & 0x20) then byte : l71 fi,                /*?*/
  261.         if (opts & 0x40) then double : l44 fi,              /*?*/
  262.         if (opts & 0x80) then double : l45 fi              /*?*/
  263.       case 15:    /* ATTDEF */
  264.         point(FALSE) : l10,
  265.         double : l40,
  266.         string : l1,
  267.         string : l3,
  268.         string : l2,
  269.         byte : l70,
  270.         if (opts & 1) then byte : l73 fi,           /*?*/
  271.         if (opts & 2) then double : l50 fi,         /*?*/
  272.         if (opts & 4) then double : l41 fi,
  273.         if (opts & 8) then double : l42 fi,
  274.         if (opts & 0x10) then byte : l7 fi,
  275.         if (opts & 0x20) then byte : l71 fi,
  276.         if (opts & 0x40) then byte : l72 fi,
  277.         if (opts & 0x80) then point(FALSE) : l11 fi,   /*?*/
  278.         if (opts & 0x100) then point(TRUE) : l210 fi,
  279.         if (opts & 0x200) then double : l38 fi        /*?*/
  280.       case 16:   /* ATTRIB */
  281.         point(FALSE) : l10,
  282.         double : l40,
  283.         string : l1,
  284.         string : l2,
  285.         byte : l70,
  286.         if (opts & 1) then byte : l73 fi,           /*?*/
  287.         if (opts & 2) then double : l50 fi,         /*?*/
  288.         if (opts & 4) then double : l41 fi,
  289.         if (opts & 8) then double : l42 fi,
  290.         if (opts & 0x10) then byte : l7 fi,
  291.         if (opts & 0x20) then byte : l71 fi,
  292.         if (opts & 0x40) then byte : l72 fi,
  293.         if (opts & 0x80) then point(FALSE) : l11 fi,   /*?*/
  294.         if (opts & 0x100) then point(TRUE) : l210 fi,
  295.         if (opts & 0x200) then double : l38 fi        /*?*/
  296.       case 17:   /* S/BEND */
  297.         long
  298.       case 19:   /* PLINE */
  299.         if (opts & 1) then byte : l70 fi,
  300.         if (opts & 2) then double : l40 fi,                   /*?*/
  301.         if (opts & 4) then byte : l71 fi,         /*?*/
  302.         if (opts & 8) then byte : l72 fi,         /*?*/
  303.         if (opts & 0x10) then byte : l73 fi,         /*?*/
  304.         if (opts & 0x20) then byte : l74 fi,         /*?*/
  305.         if (opts & 0x40) then byte : l75 fi         /*?*/
  306.       case 20:   /* VERTEX */
  307.         point(FALSE) : l10,
  308.         if (opts & 1) then double : l40 fi,           /*?*/
  309.         if (opts & 2) then double : l41 fi,           /*?*/
  310.         if (opts & 4) then byte : l70 fi,             /*?*/
  311.         if (opts & 8) then double : l50 fi           /*?*/
  312.       case 22:   /* 3DFACE */
  313.         point(!(flag & 4)) : l10,
  314.         point(!(flag & 4)) : l11,
  315.         point(!(flag & 4)) : l12,
  316.         point(!(flag & 4)) : l13
  317.       case 23:   /* DIM */
  318.         word : l1,
  319.         point(TRUE) : l10,
  320.         point(FALSE) : l11,   /*?*/
  321.         if (opts & 2) then byte : l70 fi,
  322.         if (opts & 1) then point(TRUE) : l12 fi,    /*?*/
  323.         if (opts & 4) then string : l1 fi,
  324.         if (opts & 8) then point(TRUE) : l13 fi,
  325.         if (opts & 0x10) then point(TRUE) : l14 fi,
  326.         if (opts & 0x20) then point(TRUE) : l15 fi,
  327.         if (opts & 0x40) then point(TRUE) : l16 fi,
  328.         if (opts & 0x80) then double : l40 fi,
  329.         if (opts & 0x100) then double : l50 fi,
  330.         if (opts & 0x200) then double : l51 fi,
  331.         if (opts & 0x400) then double : l52 fi,
  332.         if (opts & 0x800) then double : l53 fi
  333.       case 24:   /* VPORT */
  334.         point(TRUE) : l10,
  335.         double : l40,
  336.         double : l41,
  337.         word : l68
  338.       endswitch
  339.       check_2
  340.     )
  341.   )* : entities.
  342.  
  343. Still need to define xdata and handle. (to be continued...)
  344.  
  345. ---------------------------------------------------------------------------
  346. Last updated: Tuesday, 09-Jan-96 20:21:36 MET
  347.